package com.dongdong.controller;


import com.dongdong.model.TbAddress;
import com.dongdong.service.AddressService;
import com.dongdong.utils.Result;
import com.dongdong.vo.AddressVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    /**
     * 获取当前用户的所有地址
     * @param accessToken
     * @return
     */
    @GetMapping("/getAddressByUserId")
    public List<AddressVO> getAddressByUserId(@RequestHeader String accessToken){
        List<AddressVO> addressVOS = addressService.getAddressByUserId(accessToken);
        return addressVOS;
    }

    @GetMapping("/getAddressById")
    public TbAddress getAddressById(@RequestParam Long addrId){
        return addressService.getAddressById(addrId);
    }


    @PostMapping("/addAddress")
    public void addAddress(@RequestHeader String accessToken,@RequestBody AddressVO addressVO){
        addressService.addAddress(accessToken,addressVO);
    }
}
